package data.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;

import javax.sql.DataSource;

/**Classe utilitaire pour gerer l'acces a la base de données.
 * Utilise le fichier al22.properties.
 * @author HAL
 *
 */
public class Al22DataSource implements DataSource {

        /**
         * Url de connecxion a la base.
         */
        private static String url;
        /**
         * Driver pour la base.
         */
        private static String driver;
        /**
         * login a la base acces schema al22.
         */
        private static String login;
        /** password accès sur schema al22.
         */
        private static String password;
        /**
         * Bloc d'initialisation des properties pour acces ,a la base de données.
         */
        static {
            Properties props = new Properties();
            try {
                InputStream is =
                        Thread.currentThread().getContextClassLoader().
                        getResourceAsStream("al22.properties");
                props.load(is);
                url = props.getProperty("url");
                login = props.getProperty("login");
                password = props.getProperty("pass");
                driver = props.getProperty("driver");
                Class.forName(driver);

            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
        }

    @Override
    public PrintWriter getLogWriter() throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getLoginTimeout() throws SQLException {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void setLogWriter(PrintWriter paramArg0) throws SQLException {
        // TODO Auto-generated method stub

    }

    @Override
    public void setLoginTimeout(int paramArg0) throws SQLException {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean isWrapperFor(Class<?> paramArg0) throws SQLException {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public <T> T unwrap(Class<T> paramArg0) throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Connection getConnection() throws SQLException {
        Connection cnx = null;
        cnx = DriverManager.getConnection(url, login, password);
        return cnx;
    }

    @Override
    public Connection getConnection(String paramArg0, String paramArg1)
            throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

}
